package com.ruoyi.experiment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.experiment.domain.TeachingExperimentalEnvironment;
import com.ruoyi.experiment.service.ITeachingExperimentalEnvironmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教学实验环境Controller
 * 
 * @author 邓鑫
 * @date 2023-07-29
 */
@RestController
@RequestMapping("/experiment/environment")
public class TeachingExperimentalEnvironmentController extends BaseController
{
    @Autowired
    private ITeachingExperimentalEnvironmentService teachingExperimentalEnvironmentService;

    /**
     * 查询教学实验环境列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:environment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingExperimentalEnvironment teachingExperimentalEnvironment)
    {
        startPage();
        List<TeachingExperimentalEnvironment> list = teachingExperimentalEnvironmentService.selectTeachingExperimentalEnvironmentList(teachingExperimentalEnvironment);
        return getDataTable(list);
    }

    /**
     * 导出教学实验环境列表
     */
    @PreAuthorize("@ss.hasPermi('experiment:environment:export')")
    @Log(title = "教学实验环境", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingExperimentalEnvironment teachingExperimentalEnvironment)
    {
        List<TeachingExperimentalEnvironment> list = teachingExperimentalEnvironmentService.selectTeachingExperimentalEnvironmentList(teachingExperimentalEnvironment);
        ExcelUtil<TeachingExperimentalEnvironment> util = new ExcelUtil<TeachingExperimentalEnvironment>(TeachingExperimentalEnvironment.class);
        util.exportExcel(response, list, "教学实验环境数据");
    }

    /**
     * 获取教学实验环境详细信息
     */
    @PreAuthorize("@ss.hasPermi('experiment:environment:query')")
    @GetMapping(value = "/{teachingEnvironmentId}")
    public AjaxResult getInfo(@PathVariable("teachingEnvironmentId") Long teachingEnvironmentId)
    {
        return success(teachingExperimentalEnvironmentService.selectTeachingExperimentalEnvironmentByTeachingEnvironmentId(teachingEnvironmentId));
    }

    /**
     * 新增教学实验环境
     */
    @PreAuthorize("@ss.hasPermi('experiment:environment:add')")
    @Log(title = "教学实验环境", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingExperimentalEnvironment teachingExperimentalEnvironment)
    {
        return toAjax(teachingExperimentalEnvironmentService.insertTeachingExperimentalEnvironment(teachingExperimentalEnvironment));
    }

    /**
     * 修改教学实验环境
     */
    @PreAuthorize("@ss.hasPermi('experiment:environment:edit')")
    @Log(title = "教学实验环境", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingExperimentalEnvironment teachingExperimentalEnvironment)
    {
        return toAjax(teachingExperimentalEnvironmentService.updateTeachingExperimentalEnvironment(teachingExperimentalEnvironment));
    }

    /**
     * 删除教学实验环境
     */
    @PreAuthorize("@ss.hasPermi('experiment:environment:remove')")
    @Log(title = "教学实验环境", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teachingEnvironmentIds}")
    public AjaxResult remove(@PathVariable Long[] teachingEnvironmentIds)
    {
        return toAjax(teachingExperimentalEnvironmentService.deleteTeachingExperimentalEnvironmentByTeachingEnvironmentIds(teachingEnvironmentIds));
    }

    /**
     * 生成环境实例
     */
    @PreAuthorize("@ss.hasPermi('experiment:environment:addExample')")
    @PostMapping("/addExample/{teachingEnvironmentId}")
    public AjaxResult addExample(@PathVariable Long teachingEnvironmentId)
    {
        teachingExperimentalEnvironmentService.addExample(teachingEnvironmentId);
        return new AjaxResult(200,"生成实例成功");
    }
}
